<template>
  <div class="category_contianer">
    <my-bread :list="['商品管理','商品分类']"></my-bread>
    <el-card class="box-card">
      <el-button type="primary" @click="openAddDialog()">添加分类</el-button>
      <!-- 树状表格 -->
      <el-table
        :data="categoryList"
        style="width: 100%"
        row-key="cat_id"
        border
        :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
      >
        <el-table-column prop="cat_name" label="分类名称"></el-table-column>
        <el-table-column prop="cat_deleted" label="是否有效">
          <template slot-scope="scope">
            <i v-if="!scope.row.cat_deleted" class="el-icon-success" style="color:green"></i>
            <i v-if="scope.row.cat_deleted" class="el-icon-error" style="color:red"></i>
          </template>
        </el-table-column>
        <el-table-column prop="cat_level" label="分类等级">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.cat_level === 0">一级</el-tag>
            <el-tag v-else-if="scope.row.cat_level === 1" type="success">二级</el-tag>
            <el-tag v-else type="warning">三级</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="address" label="操作">
          <template slot-scope="scope">
            <el-button-group>
              <el-button
                size="small"
                icon="el-icon-edit"
                round
                @click="openEditDialog(scope.row)"
              >编辑</el-button>
              <el-button
                size="small"
                icon="el-icon-delete"
                round
                @click="delCate(scope.row.cat_id)"
              >删除</el-button>
            </el-button-group>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
        background
        layout="prev, pager, next"
        @current-change="paper"
        :current-page="reqParams.pagenum"
        :page-count="total"
      ></el-pagination>
      <!-- 添加分类对话框 -->
      <el-dialog title="添加分类" :visible.sync="addDialogFormVisible">
        <el-form
          :model="addForm"
          :rules="addRules"
          ref="addForm"
          label-width="80px"
          autocomplete="off"
        >
          <el-form-item label="父级分类" prop="cat_pid">
            <!-- 级联控件 -->
            <el-cascader
              v-model="selectedCateArr"
              :options="cascaderOptions"
              :props="{ expandTrigger: 'hover',value:'cat_id',label:'cat_name', checkStrictly:true}"
              clearable
              @change="handleChange"
            ></el-cascader>
          </el-form-item>
          <el-form-item label="分类名称" prop="cat_name">
            <el-input v-model="addForm.cat_name"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="addDialogFormVisible = false">取 消</el-button>
          <el-button type="primary" @click="addCat()">确 定</el-button>
        </div>
      </el-dialog>
    </el-card>
    <!-- 编辑分类对话框 -->
    <el-dialog title="编辑分类" :visible.sync="editDialogFormVisible">
      <el-form :model="editForm" :rules="editRules" ref="editForm">
        <el-form-item label="分类名称" label-width="80px" prop="cat_name">
          <el-input v-model="editForm.cat_name" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="editDialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click=" editCate()">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import mixin from "./Categories-Mixin.js";
export default {
  mixins: [mixin]
};
</script>

<style lang="less" scoped>
</style>
